import Data_writes
import External_scraping
import Internal_grabbing
import Page_scraping
import logging
import show
import Housing_information


logging.basicConfig(
    filename='logging.txt',
    level=logging.DEBUG,
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
    datefmt='%Y-%m-%d %H:%M:%S'
)


def main():
    logging.info("开始抓取数据!")
    for k in range(1,101):
        logging.info(f"第{k}页数据开始抓取!")
        r, lis = Page_scraping.page_scraping(k)
        for i in range(1,len(lis)+1):
            imglink, title, titlelink, address, housedescribe, label, price, squareprice = External_scraping.external_scraping(r, i)
            housinginformation, jiaoyi = Internal_grabbing.internal_grabbing(titlelink)
            print("第{}页数据的第{}条已经更新!".format(k, i))
            Data_writes.connection(imglink, title, titlelink, address, housedescribe, label, price, squareprice, housinginformation, jiaoyi, k, i )
            logging.info(f"第{k}页,第{i}行数据已经更新完成!房屋名称:{title} url:{titlelink}")
        print(f"这是第{k}页数据,已经更新完成")
    Housing_information.information()
    show.output()

if __name__ == '__main__':
    main()
